﻿<script>
    var _sorts = @this.RawSerialize(this.ViewBag.SortList);
    var _brands = @this.RawSerialize(this.ViewBag.BrandList); 

    var _sts = [{ id: 0, text: "未导出" }, { id:1, text: "已导出" }];

    var _sorts2 = new Array();
    var _file_domain = "@ViewBag.FileDomain";
    var uploader;

    

    $(_sorts).each(function (i, item) {
        if (item.Pid == "0") {
            _sorts2.push({ "Id": item.Id, "Title": item.Title, "Pid": item.Pid, "SortCode": item.SortCode, "ProCount": item.ProCount });

            $(_sorts).each(function (ii, item2) {
                if (item2.Pid == item.Id) {
                    _sorts2.push({ "Id": item2.Id, "Title": "     |-----" + item2.Title, "Pid": item2.Pid, "SortCode": item2.SortCode, "ProCount": item2.ProCount });
                }
            });
        }
    });




    var _vm;
    $(function () {
        var vm = new PageViewModel();
        _vm = vm;
        ko.applyBindings(vm);
        vm.init();

    });
 

    function PageViewModel()
    {
        var me = this;
        ViewModel.call(me);
        vmExtend.call(me);

        me.url = "/Wiki/CKLog/Models";
        me.deleteUrl = "/Wiki/CKLog/Delete";

        
        me.dialog = new FormDialog(me);
         
    }
    function vmExtend() {
        var me = this;
    }


    function FormDialog(vm) {
        var me = this;
        Dialog.call(me);
        
        me.onOpen = function ()
        {             
            var model = me.editModel();
            if (model)
            {
                var bindModel = $ko.toJS(model);
                me.model(bindModel);
                 
            }
            else
            {                
                me.model({ IsEnabled: true });
            }
             
        }

        me.onSave = function () {
            if (!$('#form1').formValid()) {
                return false;
            }

            var model = me.model();
            if (me.editModel()) {
                 
                $ace.post("/Wiki/CKLog/Update", model, function (result) {
                    $ace.msg(result.Msg);
                    me.close();
                    vm.dataTable.reload();
                }
                );
            }
            else
            {
                 
                $ace.post("/Wiki/CKLog/Add", model, function (result) {
                    $ace.msg(result.Msg);
                    me.close();
                    vm.loadData();
                });
            }
        }
    }

</script>
